<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    //去除重复字符串
    <script>
        var str = 'ssssstttttrrrryyy'
        var str1 = ''
        for(var i=0;i<str.length;i++){
            if(str1.indexOf(str[i]) == -1){
                str1+=str[i]
            }
        }
        console.log(str1)
        console.log(str.lastIndexOf('r',12))
    </script>

//封装添加class方法
<style>
    .active{
        background: pink;
    }
</style>

<div class="nav">你很好</div>

<script>
    var odiv = document.getElementsByTagName('div')[0]
    addClass(odiv,'active')
    function addClass(ele,classNa) {
        if(ele.classList = '') {
            ele.className+=classNa
        }
        else if(ele.className.indexOf(classNa) == -1){
            ele.className+=classNa
        }
    }
</script>

</body>
</html>